package br.edu.fasete.javaroad.model.architeture;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ArchitetureIO {
	public static void saveArchiteture(String filename, Architeture arc) {
		File arquivo = new File(filename);
		saveArchiteture(arquivo, arc);
	}
	
	public static void saveArchiteture(File arquivo, Architeture arc) {
		try {
			ObjectOutputStream saida = new ObjectOutputStream(new FileOutputStream(arquivo));
			saida.writeObject(arc);
			saida.flush();
			saida.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Architeture loadArchiteture(String filename) {
		File arquivo = new File(filename);
		return loadArchiteture(arquivo);
	}
	
	public static Architeture loadArchiteture(File arquivo) {
		Architeture arc = null;
		try {
			ObjectInputStream entrada = new ObjectInputStream(new FileInputStream(arquivo));
			arc = (Architeture) entrada.readObject();
			entrada.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}		
		return arc;
	}
	


}
